/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package gui.event.benhan;

import gui.benhan.BAChiTiet_Dialog;
import gui.benhan.BASuaThongTin_Dialog;
import gui.benhan.BATao_Full;
import gui.benhan.BAXoa_Full;
import gui.event.ulti.Util;
import java.awt.List;
import java.awt.print.PrinterException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;


import control.benhan.BAMainPanel_Ctrl;
import model.entity.BenhAn;
import gui.benhan.BAXoa_Dialog;

/**
 *
 * @author Admin
 */
public class BAMainPanel_evt {
    
    public static final void btnThemActionPerformed(JTable table){
        BATao_Full baTaoDialog = new BATao_Full(table, null, true);
        baTaoDialog.setLocationRelativeTo(null);
        baTaoDialog.setVisible(true);
    }
    
    public static final void btnSuaActionPerformed(JTable table) {
	BenhAn ba = BAMainPanel_Ctrl.selectRow(table);
        BASuaThongTin_Dialog baSuaDlg = new BASuaThongTin_Dialog(table, null, true);
        
	baSuaDlg.getTxtMaHoSo().setText("" + ba.getBaMa());
        baSuaDlg.getTxtMaBenh().setText(ba.getBenh().getBenhMa() + "");
        baSuaDlg.getTxtMaVatNuoi().setText(ba.getBenh().getBenhMa() + "");
        baSuaDlg.getjDateChooserNgayBatDau().setDate(ba.getBaNgayBd());
        baSuaDlg.getjDateChooserNgayKetThuc().setDate(ba.getBaNgayKt());
        baSuaDlg.getTaGhiChu().setText(""+ba.getBaGhiChu());
        if(ba.getBaTrangThai().equalsIgnoreCase("Còn bệnh")){
            baSuaDlg.getRbtnConBenh().setSelected(true);
        }else{
            baSuaDlg.getRbtnHetBenh().setSelected(true);
        }
        System.out.println(ba.getBaTrangThai());
        baSuaDlg.setLocationRelativeTo(null);
        baSuaDlg.setVisible(true);
    }
    
     public static final void btnInActionPerformed(JTable table) {
         try {
             table.print();
         } catch (PrinterException e) {
             Logger.getLogger(BAMainPanel_evt.class.getName()).log(Level.SEVERE, null, e);
         }
     }
     
     public static final void btnChiTietActionPerformed(JTable table) {
	BenhAn benhAn = BAMainPanel_Ctrl.selectRow(table);
        BAChiTiet_Dialog baChiTietDlg = new BAChiTiet_Dialog(null, true);
		baChiTietDlg.getTxtMaHSBA().setText(""+benhAn.getBaMa());
        baChiTietDlg.getTxtTenBenh().setText(benhAn.getBenh().getBenhTen());
        baChiTietDlg.getjDateChooserDayBĐau().setDate(benhAn.getBaNgayBd());
        baChiTietDlg.getjDateChooserDayKT().setDate(benhAn.getBaNgayKt());
        baChiTietDlg.getTxtTrangThai().setText(""+benhAn.getBaTrangThai());
        baChiTietDlg.getTaGhiChu().setText(""+benhAn.getBaGhiChu());
        
        BAMainPanel_Ctrl.loadPHieuDieuTriTheoMaHSBA(baChiTietDlg.getTblPhieuDieuTri(), benhAn.getBaMa());
        baChiTietDlg.setLocationRelativeTo(null);
        baChiTietDlg.setVisible(true);
     }
     
      public static final void btnCloseActionPerformed(JPanel pnl, JTabbedPane jTabbedPane) {
        Util.closeATab(pnl.getName(), jTabbedPane);
    }
      
      public static final void btnDeleteActionPerformed(JTable table){
        BAXoa_Full baXoaFull = new BAXoa_Full(null, true);
		BAXoa_Dialog bAXoa_Dialog = new BAXoa_Dialog(table, null, true);
        baXoaFull.setLocationRelativeTo(null);
        baXoaFull.setVisible(true);
      }
      
     public static final void btlHSBAFocusGained(java.util.List<JButton> listButtons, JTable table) {

            Util.enableListButtons(listButtons);
    }
      
       public static final void btlHSBAFocusLost(java.util.List<JButton> listButtons) {
            Util.disableListButtons(listButtons);
    }
       public static final void btnLietKeActionPerformed() {
        //TODO need DAO code here.
        //JOptionPane.showMessageDialog(null, "Can't access DB.");
    }
}
